<%@ page contentType="text/html; charset=UTF-8" %><%@ page import="java.util.*" %><%@ page import="com.ionglobal.db.*" %><%@ page import="com.ionglobal.lib.*" %><%@ page import="com.ionglobal.misc.*" %><%@ page import="com.dhec.ggs.*"%><%@ page import="java.text.SimpleDateFormat" %><%@ include file="/inc/init_include.jsp" %><%
Calendar cal = Calendar.getInstance();
int curYear = cal.get(Calendar.YEAR);
Request req = new Request(request);
int year = req.getInt("year", curYear);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String firstday = year+"-1-1";
Date fstDay = sdf.parse(firstday);
cal.setTime(fstDay);
WorkCalendar.setDatabaseSetting(WorkCalendar.DATABASE_ORACLE);
//WorkCalendar.setDatabaseSetting(WorkCalendar.DATABASE_MYSQL);
List<Date> restDays = WorkCalendar.getRestDay(dbi, year);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/calendar.css" type="text/css"
	rel="stylesheet">
<style type="text/css">
   .mainTable {
	background-color: #cccccc;
}

.header {
	background-color: #6694DF;
	font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
	font-size: 8pt;
}

.changeDate {
	cursor: hand;
	font-size: 8pt;
	font-family: "Georgia", "Times New Roman", "Times", "serif";
}

.weekDay {
	font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
	font-size: 8pt;
}

.eachDay {
	background-color: #F5F5F5;
	color: #000000;
	font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
	font-size: 8pt;
}

.weekend {
	background-color: #DBE1E3;
	color: #000000;
	font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
	font-size: 8pt;
}

.today {
	background-color: #CCD5D7;
	font-weight: bold;
}
   </style>
<script Language="JavaScript" src="../js/ajax.js"></script>
<script Language="JavaScript"> 
var year = <%=year%>;

function goYear(i){  
  year=year+i;
  window.location="workCalendar.jsp?year="+year;
}
function selectDay(obj, month, day){
  if(obj.checked){
    //alert("选择");
	//WorkCalendarAjaxService.createData(year, month, day);
	var xmlHttp = newXMLHttpRequest();
    if(xmlHttp){
		xmlHttp.open("GET", "ajaxWorkCalendar.jsp?ins=1&year="+year+"&month="+month+"&day="+day, true);
     	//xmlHttp.onreadystatechange = function(){ajaxstatus(xmlHttp)};
		xmlHttp.send(null);
	}
  }else{
    var xmlHttp = newXMLHttpRequest();
    if(xmlHttp){
		xmlHttp.open("GET", "ajaxWorkCalendar.jsp?del=1&year="+year+"&month="+month+"&day="+day, true);
     	//xmlHttp.onreadystatechange = function(){ajaxstatus(xmlHttp)};
		xmlHttp.send(null);
	}
  }
}
</script>
</head>

<body id="document">

<table width="90%" border="0" cellpadding="2" cellspacing="2"
	align="center">
	<tr>
		<td colspan="3" align="center"><span onClick="goYear(-1)"
			title="上一年" class="changeDate">&lt;&lt;</span>&nbsp;&nbsp;&nbsp;<b><%=year%>
		工作日历</b>&nbsp;&nbsp;&nbsp;<span onClick="goYear(1)" title="下一年"
			class="changeDate">&gt;&gt;</span></td>
	</tr><%
		for(int i=1;i<=4;i++){
		%>
	<tr><%
			for(int j=1;j<=3;j++){
				int weekday=cal.get(Calendar.DAY_OF_WEEK); //星期几
				int month = cal.get(Calendar.MONTH); 
	%>
		<td valign="top">
 			<table width="280" height="80" class="mainTable" border=0 cellspacing=1 cellpadding=2>
                <tr>
                    <td colspan=7 class="x-title">
                    <table width=100% cellspacing=0 cellpadding=0>
                        <tr>
                            <td align="center"><font color="#FFFFFF"><b><%=month+1%>月</b></font>
                            </td>
                        </tr>
                    </table>
                    </td>
                </tr>
                <tr>
                    <td align="center" class="weekDay">日</td>
                    <td align="center" class="weekDay">一
                    </th>
                    <td align="center" class="weekDay">二
                    </th>
                    <td align="center" class="weekDay">三
                    </th>
                    <td align="center" class="weekDay">四
                    </th>
                    <td align="center" class="weekDay">五
                    </th>
                    <td align="center" class="weekDay">六</td>
                </tr>
				<%
				int weekcount=0;
				while(cal.get(Calendar.MONTH)==month){
				%><tr><%
					for(int w=0;w<7;w++){
						int day=cal.get(Calendar.DAY_OF_MONTH);
						Date curDate = new Date(year, month, day);
						for(int k=Calendar.SUNDAY;k<weekday;k++,w++){
						//循环打空TD格%>
                    <td class="<%=w==0 || w==6?"weekend":"eachDay"%>" align="left"
                        height="30" width="40">&nbsp;
                    </td><%
						}
						weekday=0;%>
                    <td class="<%=w==0 || w==6?"weekend":"eachDay"%>" align="left"
                        height="30" width="40">
                     <input type="checkbox" name="id" value=""
                        onClick="selectDay(this, <%=month+1%>, <%=day%>);"<%=restDays.contains(cal.getTime())?" checked":""%>><%=day%>
                    </td><%
						cal.add(Calendar.DAY_OF_MONTH, 1);
						if(cal.get(Calendar.MONTH)!=month){
							w++;
							for(int l=w;l<7;l++,w++){
								%>
                    <td class="<%=l==0 || l==6?"weekend":"eachDay"%>" align="left"
                        height="30" width="40">&nbsp;
                    </td><%
							}
						}
					}
					weekcount++;
					%>
                </tr><%
				}
				for(int c=weekcount;c<6;c++){
				%>
                <tr>
                    <td class="weekend" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="eachDay" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="eachDay" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="eachDay" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="eachDay" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="eachDay" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                    <td class="weekend" align="left"
                        height="30" width="40">&nbsp;
                    </td>
                </tr>
                <%	
				}
				%>
            </table>
		</td><%
			}
		%>
	</tr><%
		}
	%>
</table>
</body>
</html>
<%@ include file="/inc/init_free.jsp" %>